package com.mida.dms.knw.controller;



import com.mida.dms.knw.entity.DtUseSpace;
import com.mida.dms.knw.entity.vo.DtUseSpaceVo;
import com.mida.dms.knw.service.DtUseSpaceService;
import com.mida.dms.knw.vo.DtUseSpacePageVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：wang xiao le
 * @description：TODO
 * @date ：2021/3/22 10:53
 */
@RestController
@RequestMapping("dtUseSpace")
@CrossOrigin
public class DtUseSpaceController {

    @Autowired
    private DtUseSpaceService dtUseSpaceService;



    /**
     * 1、添加授权空间
     *
     * @param dtUseSpaceVo
     * @return
     */
    @PostMapping(value = "add",consumes = {"application/json"})
    public ActionResult add(@RequestBody DtUseSpaceVo dtUseSpaceVo) {
        System.out.println("dtUseSpaceVo = " + dtUseSpaceVo);
        return dtUseSpaceService.add(dtUseSpaceVo);
    }


    /**
     * 2、更新授权空间
     *
     * @param dtUseSpaceVo
     * @return
     */
    @PostMapping(value = "update",consumes = {"application/json"})
    public ActionResult update(@RequestBody DtUseSpaceVo dtUseSpaceVo) {
        return dtUseSpaceService.update(dtUseSpaceVo);
    }

    /**
     * 3、删除授权空间
     *
     * @param useSpaceSoid 授权空间soid
     * @return null
     */
    @GetMapping(value = "/delete")
    public ActionResult delete(@RequestParam("useSpaceSoid") long useSpaceSoid) {
        return dtUseSpaceService.delete(useSpaceSoid);
    }

    /**
     * 4、获取单个授权空间
     *
     * @param useSpaceSoid 授权空间soid
     * @return
     */
    @GetMapping("get")
    public ListResult<DtUseSpaceVo> get(@RequestParam("useSpaceSoid") long useSpaceSoid) {
        return dtUseSpaceService.get(useSpaceSoid);
    }

    /**
     * 5、分页查询授权空间
     * @param vo
     * @return
     */
    @ApiOperation(value = "分页查询授权空间", notes = "分页查询授权空间")
    @PostMapping(value = "/findPage",produces = { "application/json;charset=UTF-8" })
    public ListResult<PageResultVo<DtUseSpaceVo>> findPage(@RequestBody DtUseSpacePageVo vo) {
        return dtUseSpaceService.findPage(vo);
    }

    /**
     * 6、授权空间名称重复性校验
     */
    @GetMapping(value = "/checkName")
    public ActionResult checkName(@RequestParam(value = "name", required = true) String name,
                                  @RequestParam(value = "useSpaceSoid", required = false) Long useSpaceSoid) {
        return dtUseSpaceService.checkName(name,useSpaceSoid);
    }

    /**
     * 7、更改授权空间状态
     *
     * @param useSpaceSoid 授权空间soid
     * @param status       状态soid
     * @return
     */
    @GetMapping("/updateStatus")
    public ActionResult updateStatus(@RequestParam(value = "status", required = true) Long status,
                                     @RequestParam(value = "useSpaceSoid", required = false) Long useSpaceSoid) {
        return dtUseSpaceService.updateStatus(status, useSpaceSoid);
    }

    /**
     * 8、授权空间下拉(查询所有授权空间)
     * @return
     */
    @GetMapping("/findAll")
    public ListResult<List<DtUseSpace>> findAll(){
        return dtUseSpaceService.findAll();
    }




}
